package com.woniuxy.trade.service;

import com.woniuxy.common.enums.RabbitEnum;
import com.woniuxy.common.utils.RedisUtils;
import com.woniuxy.trade.config.SmsTemplate;
import com.woniuxy.trade.entity.Orders;
import com.woniuxy.trade.entity.User;
import com.woniuxy.trade.mapper.OrderMapper;
import com.woniuxy.trade.mapper.ProductMapper;
import com.woniuxy.trade.mapper.RoomMapper;
import com.woniuxy.trade.mapper.UserMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrdersService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    ProductMapper productMapper;
    @Autowired
    RoomMapper roomMapper;
    @Autowired
    RedisUtils redisUtils;
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    SmsTemplate smsTemplate;
    public void sendMessage(int ordersId) {
        Orders orders = orderMapper.selectByPrimaryKey(ordersId);
        User user = userMapper.selectByPrimaryKey(orders.getBuyuserid());
        //先发送MQ消息，订单付款倒计时
        System.err.println("付款倒计时：60s");
        rabbitTemplate.convertAndSend(RabbitEnum.ORDER_NORMAL_EXCHANGE,RabbitEnum.ORDER_NORMAL_ROUTING_KEY,ordersId);
        //再向该用户发送短信
        System.err.println("发送短信:"+user.getPhone());
        smsTemplate.sendSms(user.getPhone(),"000");
        //用户付款业务
    }
}
